<table id="menuTreeGrid" data-options="fit:true, border:false"></table>
<div id="RoleToolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addItem(this)">添加</a>
    <a class="datagrid-btn-separator"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyItem(this)">删除</a>
</div>
<script type="text/javascript">
    var menuTreeGrid = $('#menuTreeGrid');
    menuTreeGrid.treegrid({
        url:'{:U("menu/tree")}',
        idField:'id',
        toolbar: "#RoleToolbar",
        treeField:'text',
        fitColumns: true,
        singleSelect: false,
        columns:[[
            {field:'id',checkbox:true},
            {field:'text', title:'菜单名称',width:180},
            {field:'name', title:'操作节点',width:180},
            {field:'display', title:'是否显示',width:80, align:'center', formatter: function(value){
                if(value == '1') return '<font color="red">是</font>';
                return '否';
            }},
            {field:'querys', title:'参数',width:80},
            {field:'orderby', title:'排序',width:80},
            {field:'remark', title:'描述',width:80},
            {field:'pass', title:'是否检查权限',width:80, align:'center', formatter: function(value){
                if(value == '1') return '<font color="red">是</font>';
                return '否';
            }},
            {field: 'mid', title: '操作', width: 80, align: 'center', formatter: function(value){
                var ctrs = ['<span title="编辑" class="images-btn icon-edit" onclick="editItem(' + value + ', this)"></span>'];
                return ctrs.join(' ');
            }}
        ]]
    });

    function editItem(itemid, element){
        blur(element);
        easyui.dialog({
            title: '编辑菜单',
            width: 800,
            height: 500,
            href: "{:U('menu/edit')}",
            data: {itemid: itemid},
            handler: function(){
                menuTreeGrid.treegrid('reload');
            }
        });
    }

    function addItem(element){
        blur(element);
        easyui.dialog({
            title: '添加菜单',
            width: 800,
            height: 500,
            href: "{:U('menu/add')}",
            handler: function(){
                menuTreeGrid.treegrid('reload');
            }
        });
    }

    function destroyItem(element){
        blur(element);
        var rows = menuTreeGrid.treegrid('getSelections');
        var items = [];
        for(var i = 0; i < rows.length; i++){
            items.push(rows[i].menu_id);
        }
        items = items.join(',');
        if(empty(items)){
            easyui.alert('请选择需要删除的菜单！');
            return false;
        }
        easyui.confirm('确认删除所选菜单吗？', function(){
            easyui.ajaxCall('{:U("menu/drop")}', {items: items}, function(result){
                try{
                    if(!result.status){
                        easyui.alert(result.info);
                    }
                    menuTreeGrid.treegrid('reload');
                }catch (e){}
            });
        });
    }
</script>